﻿#include "../../libcat/include/cat-module.hpp"
#include "mode1_standard.hpp"

const char* get_name() {
	return u8"标准模式";
}
const char* get_default_config_name() {
	return u8"data\\standard\\标准模式示例.json";
}

void* Init(cat_data_t* settings) {

	standard::GetInstance()->Init(settings->json);

	return settings;
}

void* Release() {

	standard::GetInstance()->Release();
	
	return NULL;
};

void* Run(void* _window) {

	cat_window* cwindow = (cat_window*)_window;

	standard::GetInstance()->Draw(cwindow);

	return _window;
};

void* MouseMove(const cat_mouse_move_event* m) {
	standard::GetInstance()->OnMouseMove(m->x,m->y);
	return NULL;
}

void* OnMouseClick(const cat_mouse_click_event* event, bool mouse_up) {
	standard::GetInstance()->OnMouseClick(event, mouse_up);
	return NULL;
};
void* OnKeyPress(const cat_key_event* event, bool key_up) {
	standard::GetInstance()->OnKeyPress(event->native_vkey, key_up);
	return NULL;
};
void* OnForceMouseMove(const cat_mouse_move_event* event) {
	standard::GetInstance()->OnForceMouseMove(event->x,event->y);
	return NULL;
};

void* OnUpdata(cat_data_t* settings) {

	standard::GetInstance()->Updata(settings->json);

	return settings;
}

/*声明一个模块*/
CAT_DECLARE_MODULE()
bool cat_module_load() {
	cat_source_info standard{};
	standard.id = 1;
	standard.type = CAT_SOURCE_TYPE_MODE;
	standard.Init = Init;
	standard.Update = OnUpdata;
	standard.Release = Release;
	standard.Run = Run;
	standard.OnMouseMove = MouseMove;
	standard.OnForceMouseMove = OnForceMouseMove;
	standard.OnMouseClick = OnMouseClick;
	standard.OnKeyPress = OnKeyPress;
	standard.get_name = get_name;
	standard.get_default_config_name = get_default_config_name;

	cat_register_source(&standard);
	return true;
}